#ifndef MAINWINDOW_H
#define MAINWINDOW_H


#include "findreplacedialog.h"
#include "aboutdialog.h"
#include "syntaxhighlighter.h"
#include <QMainWindow>
#include <QTextDocument>
#include <QLabel>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
#include <QStandardPaths>
#include <QVBoxLayout>
#include <QFontDialog>
#include <QColorDialog>
#include <QScreen>
#include <QTextCursor>
#include <QToolTip>
#include <QTimer>
#include <QCloseEvent>
#include <QMetaEnum>
#include <QSettings>


QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

class MainWindow : public QMainWindow
{
    Q_OBJECT


public:
    MainWindow(QWidget *parent = nullptr);
    ~MainWindow();

private slots:


    void on_actionNew_triggered();
    void on_actionOpen_triggered();
    bool on_actionSave_triggered();
    bool on_actionSaveAs_triggered();





    void on_selectAllAction_triggered();

    void on_pasteAction_triggered();

    void on_copyAction_triggered();

    void on_cutAction_triggered();

    void on_redoAction_triggered();

    void on_undoAction_triggered();

    void on_deleteAction_triggered();

    void on_fontAction_triggered();

    void on_colorAction_triggered();

    void on_findAction_triggered();
    void on_replaceAction_triggered();
    void findText(const QString &text, QTextDocument::FindFlags flags);
    void replaceText(const QString &find, const QString &replace, QTextDocument::FindFlags flags);
    void replaceAllText(const QString &find, const QString &replace, QTextDocument::FindFlags flags);

    void positionFindDialog();


    void on_aboutAction_triggered();

    void on_shortcutConfigAction_triggered();
   void applyShortcuts(const QHash<QString, QKeySequence>& shortcuts);
private:
    Ui::MainWindow *ui;
    FindReplaceDialog *findDialog;
    QString currentFile;  // 当前打开的文件路径
    QLabel *positionLabel;
    QLabel *encodingLabel;
    AboutDialog *aboutDialog = nullptr;
    QTimer *autoSaveTimer;
    CppHighlighter *highlighter = nullptr;
    QHash<QString, QAction*> shortcutActions;


    void setupSyntaxHighlighting(const QString &filePath);





    QString autoSavePath();

    void autoSave();
    void loadAutoSave();
    void myCloseEvent(QCloseEvent *event);
    bool maybeSave();     // 检查是否需要保存
    void loadFile(const QString &fileName);  // 加载文件
    void saveFile(const QString &fileName);  // 保存文件
    void initStatusBar();
    void updateStatusBar();
    void initAbout();
    void updateLanguageMenu();


    void setupShortcutActions();
    void loadShortcuts();
    void saveShortcuts();
};
#endif // MAINWINDOW_H
